package com.tgy.set;

import com.tgy.tree.RBTree;
import com.tgy.tree.Visitor;

/**
 * @Author: tgy
 * @Date: 2020-09-22 16:27
 */
public class TreeSet<E> implements Set<E> {

    private RBTree<E> rbTree = new RBTree<>();

    @Override
    public int size() {


        return rbTree.size();
    }

    @Override
    public boolean isEmpty() {

        return rbTree.isEmpty();
    }

    @Override
    public void clear() {

        rbTree.clear();
    }

    @Override
    public boolean contains(E element) {

        return rbTree.contains(element);
    }

    @Override
    public void add(E element) {

        rbTree.add(element);
    }

    @Override
    public void remove(E element) {

        rbTree.remove(element);
    }

    @Override
    public void traversal(Visitor<E> visitor) {

        rbTree.inorderRecursionTraversal(new com.tgy.tree.Visitor<E>() {
            @Override
            public boolean visit(E element) {
                stop = visitor.visit(element);
                return false;
            }
        });
    }
}
